#########################
#   Author : Leon yu    #
#   Date : 2025/06/13   #
#   Id : SM2772         #
#########################
from apiRespsAnalyze import *

def queryTaxDetailReportResult(startTime, endTime):
    result = dict()
    result['totalTaxAmount'] = 0
    result['taxDetailInfo'] = list()
    queryTaxDetailReport = analyzeQueryTaxDetailReport(startTime=startTime, endTime=endTime)
    if queryTaxDetailReport['list']:
        result['totalTaxAmount'] = queryTaxDetailReport['totalTaxAmount']['amount']
        for item in queryTaxDetailReport['list']:
            resultDict = dict()
            taxId = f"{item['taxName']}_{item['taxRate']}"
            resultDict[taxId] = {
                                            'taxableAmount' : item['taxableAmount']['amount'],
                                            'taxAmount' : item['taxAmount']['amount']
                                        }
            result['taxDetailInfo'].append(resultDict)
        result['taxDetailInfo'] = sorted(result['taxDetailInfo'], key=lambda x: list(x.keys())[0])
    return result

# startTime = 1718557200000
# endTime = 1718643599000
# result = queryTaxDetailReportResult(startTime, endTime)
# print(result)
